//
//  MyActivityViewController.m
//  UI_豆瓣
//
//  Created by WangZe on 15/10/14.
//  Copyright © 2015年 王泽龙. All rights reserved.
//

#import "MyActivityViewController.h"
#import "ActivityList.h"
#import "ActivityListCell.h"
#import "DatabaseHandle.h"
#import "UIImageView+WebCache.h"
#import "ActivityDetailsViewController.h"
@interface MyActivityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *arr;
@end

@implementation MyActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:87 / 255.0 green:137 / 255.0 blue:157 / 255.0 alpha:1];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.title = @"我的活动";
    self.tableView.rowHeight = 250;
    
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.arr = [NSMutableArray array];
    self.arr = [[DatabaseHandle shareDatabaseHandle] selectAllActivity];
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ActivityDetailsViewController *actDetailVC = [[ActivityDetailsViewController alloc] init];
    [self.navigationController pushViewController:actDetailVC animated:YES];
    ActivityList *act = self.arr[indexPath.row];
    actDetailVC.strURL = act.adapt_url;
    [actDetailVC release];
    actDetailVC.act = act;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    ActivityListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[ActivityListCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    ActivityList *act = self.arr[indexPath.row];
    cell.labelTitle.text = act.title;
    cell.labelAdress.text = act.address;
    NSString *str1 = [act.begin_time substringWithRange:NSMakeRange(5, 11)];
    NSString *str2 = [act.end_time substringWithRange:NSMakeRange(5, 11)];
    
    cell.labelTime.text = [NSString stringWithFormat:@"%@ -- %@", str1, str2];
    NSString *str = [NSString stringWithFormat:@"类型: %@", act.category_name];
    cell.labelType.text = str;
    NSString *strtwo = [NSString stringWithFormat:@"感兴趣: %@  参加: %@", act.wisher_count, act.participant_count];
    cell.labelLike.text = strtwo;
    cell.imageTime.image = [UIImage imageNamed:@"time.png"];
    cell.imageAdress.image = [UIImage imageNamed:@"adress.png"];
    cell.imageType.image = [UIImage imageNamed:@"type.png"];
    [cell.imageMovie sd_setImageWithURL:[NSURL URLWithString:act.image]];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
